<?php

/**
 * Inicializuje spojeni
 */
function connect() {    
    if (!isset($GLOBALS["connection"])) {
        $connection = mysql_connect(Settings::$DBhost, Settings::$DBusr, Settings::$DBpwd);
        if (!$connection) {
            die('Could not connect: ' . mysql_error());
        }
        $db_selected = mysql_select_db(Settings::$DBname, $connection);
        if (!$db_selected) {
            die('Can\'t use ' . Settings::$DBname . ' : ' . mysql_error());
        }
        $GLOBALS["connection"] = $connection;
    }
}

function getCon(){
    return $GLOBALS["connection"];
}

function close() {
    mysql_close(getCon());
}

function mq($query) {
    $result = mysql_query($query, getCon());
    if (Settings::$sqlDebug && ($result == 0)) {
        insertSQLDebug($query);
    }
    return $result;
}

?>
